package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.LeaseAgreement;
import com.atguigu.lease.web.admin.mapper.*;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import com.atguigu.lease.web.admin.vo.agreement.AgreementQueryVo;
import com.atguigu.lease.web.admin.vo.agreement.AgreementVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * @author liubo
 * @description 针对表【lease_agreement(租约信息表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
@RequiredArgsConstructor
public class LeaseAgreementServiceImpl extends ServiceImpl<LeaseAgreementMapper, LeaseAgreement> implements LeaseAgreementService {

    private final LeaseAgreementMapper leaseAgreementMapper;

    private final ApartmentInfoMapper apartmentInfoMapper;

    private final RoomInfoMapper roomInfoMapper;

    private final PaymentTypeMapper paymentTypeMapper;

    private final LeaseTermMapper leaseTermMapper;

    @Override
    public IPage<AgreementVo> pageAgreementByAgreementQuery(Page<AgreementVo> page, AgreementQueryVo queryVo) {
        return leaseAgreementMapper.pageAgreementByAgreementQuery(page,queryVo);
    }

    @Override
    public AgreementVo getAgreementById(Long id) {
        AgreementVo agreementVo = new AgreementVo();
        // 1. leaseAgreement
        LeaseAgreement leaseAgreement = baseMapper.selectById(id);
        BeanUtils.copyProperties(leaseAgreement,agreementVo);

        // 2. 其他相关
        agreementVo.setApartmentInfo(apartmentInfoMapper.selectById(leaseAgreement.getApartmentId()));
        agreementVo.setRoomInfo(roomInfoMapper.selectById(leaseAgreement.getRoomId()));
        agreementVo.setPaymentType(paymentTypeMapper.selectById(leaseAgreement.getPaymentTypeId()));
        agreementVo.setLeaseTerm(leaseTermMapper.selectById(leaseAgreement.getLeaseTermId()));
        return agreementVo;
    }
}




